package com.hbl.xyl.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class AppLogin {
    public static void main(String[] args)throws Exception{
        Scanner scanner=new Scanner(System.in);

        System.out.print("请输入账号：");
        String name=scanner.nextLine();

        System.out.print("请输入密码：");
        String password=scanner.nextLine();

        login(name,password);
    }
    public static void login(String n,String p)throws Exception{
        System.out.println("username="+n);
        System.out.println("password="+p);
        String sql="SELECT id FROM `user` WHERE name='"+n+
                "'AND `password`='"+p+"'";
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String username = "root";
        String password = "rootx0105";
        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();
        ResultSet set=statement.executeQuery(sql);
        if (set.next()){
            System.out.println("登录成功！");
        }else{
            System.out.println("登录失败！");
        }




            }
        }
